﻿using System;
using Flagwind.Options;
using Flagwind.Options.Configuration;

namespace Flagwind.Data.Configuration
{
	public class ProviderElement : OptionConfigurationElement
	{
		#region 常量定义

		private const string XML_NAME_ATTRIBUTE = "name";
		private const string XML_TYPE_ATTRIBUTE = "type";
		private const string XML_CONNECTION_STRING_ATTRIBUTE = "connectionString";

		#endregion

		#region 公共属性

		[OptionConfigurationProperty(XML_NAME_ATTRIBUTE, Behavior = OptionConfigurationPropertyBehavior.IsKey)]
		public string Name
		{
			get
			{
				return (string)this[XML_NAME_ATTRIBUTE];
			}
			set
			{
				if(string.IsNullOrWhiteSpace(value))
				{
					throw new ArgumentNullException();
				}
				this[XML_NAME_ATTRIBUTE] = value;
			}
		}

		[OptionConfigurationProperty(XML_TYPE_ATTRIBUTE, DefaultValue = "SqlServer")]
		public string Type
		{
			get
			{
				return (string)this[XML_TYPE_ATTRIBUTE];
			}
			set
			{
				if(string.IsNullOrWhiteSpace(value))
				{
					throw new ArgumentNullException();
				}
				this[XML_TYPE_ATTRIBUTE] = value;
			}
		}

		[OptionConfigurationProperty(XML_CONNECTION_STRING_ATTRIBUTE, Behavior = OptionConfigurationPropertyBehavior.IsRequired)]
		public string ConnectionString
		{
			get
			{
				return (string)this[XML_CONNECTION_STRING_ATTRIBUTE];
			}
			set
			{
				if(string.IsNullOrWhiteSpace(value))
				{
					throw new ArgumentNullException();
				}
				this[XML_CONNECTION_STRING_ATTRIBUTE] = value;
			}
		}

		#endregion
	}
}